const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  publicPath: '/',
  configureWebpack: {
    devServer: {
      host: 'localhost',
      port: 8081,
      open: true,
      proxy: {
        '/api': {
          // target: 'http://39.99.129.23:5000/', // 后台接口域名
          target: 'http://127.0.0.1:5000',
          changeOrigin: true, //是否跨域
          ws: true, //如果要代理 websockets，配置这个参数
          secure: false,
          pathRewrite: {
            '^/api': ''
          }
        },
      }
    },
  },
  chainWebpack: config => {
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
    config.module
      .rule('image')
      .test(/\.ico$/)
      .use('url-loader')
      .loader('url-loader')
      .end()
  },
  lintOnSave: true,
}